package com.atzx.domain;

import java.util.Scanner;

/**
 * @author hello
 * @date 2024-2-2 上午 9:34
 */
public class ScannerTest {

    public static void main(String[] args) {
        jiecheng();
    }

    //求数字阶乘(for循环版)
    public static void fn(int num){
        if (num < 0){
            System.out.println("负数没有阶乘");
            return;
        }
        if (num == 0){
            System.out.println("0的阶乘为1");
            return;
        }
        long result = 1;
        for (int i = 2; i <= num; i++){
            result *= i;
        }
        System.out.println("数字"+num+"的阶乘为"+result);
    }

    public static void jiecheng(){
        System.out.print("请输入一个数字:");
        int num = new Scanner(System.in).nextInt();
        fn(num);
    }
}
